import {hrAjax as proFetch} from 'src/hrpub/common/utils/utils';
import {toast} from 'nc-lightapp-front'
//hi_psndoc_deptchg/hi_psndoc_part/hi_psndoc_dimission取行上的pk_psnjob,其他的取pk_psndoc_sub
const mainTables = ['hi_psndoc_deptchg', 'hi_psndoc_part', 'hi_psndoc_dimission'];

export default function deleteLine(record, index) {
    const {areaCode} = this.state;
    const {isIncHisPartJob, selectedPsn, orgVal, editTable, func_type} = this.props;

    const pkField = mainTables.indexOf(areaCode) > -1 ? 'pk_psnjob' : 'pk_psndoc_sub';
    const pk_sub = record.values[pkField].value;

    let postData = {
        areaCode,
        func_type,
        isIncHisPartJob,
        pk_org: orgVal.refpk,
        pk_psnjob: selectedPsn,
        pk_sub
    };

    return proFetch({
        url: '/nccloud/hrtrn/pub/RecordsDelLineDoAction.do',
        body: postData,
    })
        .then((res) => {
            if (res.success) {
                toast({color: "success", content: this.props.json['hi6007-000006']});
                if (!res.data) {
                    //getMainTableData(); NC中兼职记录删除后不需要刷新数据
                    //editTable.deleteTableRowsByIndex(areaCode, index);
                    this.getSubTableData(selectedPsn)
                } else {
                    editTable.setTableData(areaCode, {
                        rows: res.data[areaCode].rows
                    });
                }
            }
        });
}
